Repository navigation
Sleep: prompt to extend early-ended night records bounded by Bedtime - #149
Open
foureight84 wants to merge 3 commits into
Open
foureight84 wants to merge 3 commits into
foureight84 wants to merge 3 commits into
Conversation
When the ring closes its last sleep record early while Android Bedtime
stays active for 15-120 minutes with no steps after a post-Bedtime full
sync, surface a confirmable prompt on the Sleep screen ("Were you still
asleep?") instead of extending silently. Tapping Extend opens the
existing SleepRecordEditDialog pre-filled with the Bedtime end time
(snapped to the record's minute grid and clamped to 7 PM / 120m limits);
tapping No dismisses the prompt for that ring record (pruned at 45d).
…il prompt Fix SleepScore.calculate's span calculation when ADDED blocks are present: measure span across the ring's own measured blocks instead of session.spanMinutes, so outward extensions keep the same coverage ratio on 0-awake nights (fixing the 81 -> 75 score drop on Nov 16) and don't dilute awakePct, while preserving interior between-record gaps (#106). Enrich SleepTailSuggestion with non-demo heart-rate samples inside the suggested extension gap and the night's mean HR so SleepTailSuggestionCard can surface readings like "Heart rate at 08:00: 58 bpm · night avg 59 bpm" (or compact list / avg+range summary when denser HR sampling is present).
…and UI Address independent review findings across YCBT sync, tail detection, ViewModel concurrency, and Sleep UI: - Prevent partial YCBT syncs (syncSleepNow, querySleep, syncVitalsHistory) from emitting HistorySyncFinished so lastFullSyncAt only advances once SPORT and HEART history have synced too. - Require non-null lastFullSyncAt >= bedtimeEnd, intraday step-bucket support with family-aware bucket duration (1m JRing, 15m YCBT/Colmi), at least one aligned observable bucket inside the gap, and no deleted trailing phantom record in the gap. - Prefer primary/longest sleep session over daytime DND naps, check session overlaps through grid-rounded suggestedEndAt, serialize SleepViewModel rebuild() jobs to prevent dismissal resurrection or day/range races, deduplicate night HR per minute, exclude post-Bedtime HR, show raw bedtimeEndedAt in body copy, and use FlowRow for actions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #148
Summary
When a YCBT ring closes its final sleep record early while Android Bedtime/DND stays active with no steps before Bedtime ends, lying still looks identical to an idle ring sensor. Rather than modifying the night silently, this adds a confirmable "Were you still asleep?" prompt on the Sleep screen that hands off to the existing
SleepRecordEditDialog(#106) pre-filled with the suggested end time.Behavior & guardrails
SleepTailSuggestionDetector):lastFullSyncAt >= bedtimeEnd(when a device sync timestamp is present) and observesdeviceDao().currentFlow()lastFullSyncAtinSleepViewModel.initso the Sleep tab updates immediately once a post-Bedtime sync completes (even when no new sleep rows arrived).lastRun.endAtandbedtimeEndto 15–120 minutes (MAX_OUTWARD_EXTENSION_MINUTES).ActivityBucketEntity(15-min bucket) lies wholly inside(lastRun.endAt .. bedtimeEnd](startEpoch >= lastRun.endAt && startEpoch + 15m <= bedtimeEnd), ignoring pre-end get-up buckets and wake-up straddling buckets.ADDED) or manually edited (MeasurementDeletionDao.getSleepEdit) records, dismissed records, and cases where another non-demo session overlaps(lastRun.endAt, bedtimeEnd).suggestedEndAtonto the ring record's minute grid and enforcesrecordEditLimits(120m outward cap & 7 PM waking-day boundary viaclampEndPick), rechecking the 15-min minimum after clamping.SleepTailSuggestionStore):"No"dismissals keyed bysessionDate_recordStartAtwith 45-day pruning and immutableStringSetcopies.SleepScreen, EN + RU):SleepTailSuggestionCardunderSessionHeroon matching Day-view single or carousel pages.SleepRecordEditDialogwithinitialEndAt = suggestedEndAt(keeping the dialog editable and immediately saveable); tapping No hides and remembers dismissal for that record.SleepTailSuggestionTestcovering reporter examples (Oct 12 / Nov 3 / Nov 15), interior step suppression & bucket boundaries, Bedtime/sync/gap/edit/dismissal/demo/multi-session/7 PM-clamp edge cases, and store key pruning.